package com.mail.portal.modular.controller;

import com.mail.portal.common.controller.BaseController;
import com.mail.portal.modular.model.News;
import com.mail.portal.modular.model.ProductCategory;
import com.mail.portal.modular.service.IBannerService;
import com.mail.portal.modular.service.INewsService;
import com.mail.portal.modular.service.IProductCategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 创建人： Shi Heng
 * 创建时间：2018-04-03 12:17
 * QQ：374696376
 * Description：首页控制器
 */
@Controller
public class IndexController extends BaseController {

    @Resource
    private IProductCategoryService productCategoryService;

    @Resource
    private IBannerService bannerService;

    @Resource
    private INewsService newsService;


    /**
     * 跳转到主页
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) {
        List<ProductCategory> categories = productCategoryService.selectAll();
        List<Map<String, Object>> banners = bannerService.list("");
        List<News> newss = newsService.selectAll();
        model.addAttribute("categories", categories);
        model.addAttribute("banners", banners);
        model.addAttribute("newss", newss);
        return "/index.html";
    }

    @RequestMapping(value = "/index.html", method = RequestMethod.GET)
    public String index_() {
        return REDIRECT + "/";
    }
}
